﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    ViewBag.Title = "ZKTS";
    Layout = null;
}
@{
    if (Model.StandardConfig == null)
    { 
    <text>考核目标未配置</text>
        return;
    }
    List<dynamic> list = new List<dynamic>();
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {

        list.Add(new
        {
            时间 = dt,
            考核目标 = Model.GetConfig(dt.Year, dt.Month).事实流失率目标,
            事实流失率 = Model.GetAvgSSKHLSL(dt.Year, dt.Month)
        });
    }

    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.Width = 600;
    ChartModel.Height = 400;
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.IsRate = true;
    ChartModel.YAxis = "百分率";

    foreach (var item in list.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "考核目标";
    foreach (var item in list)
    {
        series.Data.Add(item.考核目标);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "事实流失率";
    foreach (var item in list)
    {
        series1.Data.Add(item.事实流失率);
    }
    ChartModel.Serieses.Add(series1);

    var 服务顾问人数 = Model.SADayData.GroupBy(o => o.EmployeeId).Count();

    int 六个月未来店客户数 = Model.MonthTarget.Sum(o => o.LGYWHCZS) + Model.SADayData.Sum(o => o.XZLGYWHCS - o.LSKHCXHCS);
    var 六个月未来店客户数平均 = 服务顾问人数 == 0 ? 0 : Math.Round(((decimal)六个月未来店客户数 / 服务顾问人数), 0, MidpointRounding.AwayFromZero);

    var 分管的保有客户数 = Model.MonthTarget.Sum(o => o.SYMFGKHZS_LastMonthManageCustomerNum) + Model.SADayData.Sum(o => o.BYAKZCKKHS_ACard2CCard) - 六个月未来店客户数;
    var 分管的保有客户数平均 = 服务顾问人数 == 0 ? 0 : Math.Round(((decimal)分管的保有客户数 / 服务顾问人数), 0, MidpointRounding.AwayFromZero);


    Model.SADayDatas = Model.SADayData;
    Model.MonthTargets = Model.MonthTarget;
    Model.StandardConfigs.Add(Model.StandardConfig);
    
}
<div style="height: 100%; overflow: auto">
    @Html.Action("ReportBar", "Common", Model.BarModel)
    <div style="position: relative; width: 100%">
        <div class="pagetitle">
            事实流失率对比</div>
        <table width="100%">
            <tr>
                <td style="width: 50px">
                    &nbsp;
                </td>
                <td valign="top">
                    <p style=" padding-bottom:15px; font-size:15px;">@(Model.BarModel.Month.Month)月事实流失率</p>
                    <table class="reporttable" style="border-collapse: collapse;">
                        <thead>
                            <tr>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        售 后 前 台 接 待 姓 名
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        接 待 前 台 职 业 资 质
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        分    管   的  保   有   客  户  数

                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                       六 个  月  未  回  厂  客  户  数

                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        事 实   客   户   流   失   率
                                    </div>
                                </th>
                                
                            </tr>
                        </thead>
                        @foreach (var item in Model.SADayData.GroupBy(o => o.EmployeeId))
                        {
                            var itemMonthTarget = Model.MonthTarget.Where(o => o.EmployeeId == item.Key).FirstOrDefault();
                            if (itemMonthTarget == null)
                            {
                                itemMonthTarget = new S4Store.Domain.AfterSaleKpi.AfterSaleServiceAdvisorMonthTarget();
                            }

                            int 六个月未来店客户数1 = itemMonthTarget.LGYWHCZS + item.Sum(o => o.XZLGYWHCS - o.LSKHCXHCS);

                            var 分管的保有客户数1 = itemMonthTarget.SYMFGKHZS_LastMonthManageCustomerNum + item.Sum(o => o.BYAKZCKKHS_ACard2CCard) - 六个月未来店客户数1;

                            
                            <tr>
                                <td>@item.FirstOrDefault().Employee.Name
                                </td>
                                <td>@(item.FirstOrDefault().Employee.WorkYear)年
                                </td>
                                <td>@分管的保有客户数1
                                </td>
                                <td>
                                    @六个月未来店客户数1
                                </td>
                                <td @if (Model.StandardConfig.事实流失率目标 < Model.GetSSKHLSL(item.Key, Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                                    {
                                    <text> style="background:#ff1100"</text>
                                    }>
                                    @Model.GetSSKHLSL(item.Key, Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                                </td>
                                
                            </tr>
                        }
                        <tr>
                            <td colspan="2">
                                服务接待平均数
                            </td>
                            <td>
                            @分管的保有客户数平均
                            </td>
                            <td>
                            @六个月未来店客户数平均
                            </td>
                            <td @if (Model.StandardConfig.事实流失率目标 < Model.GetAvgSSKHLSL(Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                                    {
                                    <text> style="background:#ff1100"</text>
                                    }>
                                 @Model.GetAvgSSKHLSL(Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                            </td>
                            
                        </tr>
                        <tr>
                            <td colspan="2">
                                服务接待目标总数
                            </td>
                            <td>
                                @分管的保有客户数
                            </td>
                            <td>
                                @六个月未来店客户数
                            </td>
                               
                            <td>
                                @(Model.StandardConfig.事实流失率目标)%
                            </td>
                            
                        </tr>
                    </table>
                </td>
                <td>
                    @Html.Partial("../Chart/Line", ChartModel)
                </td>
            </tr>
        </table>
    </div>
</div>
